package com.hiray.taglayoutmanager;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.hiray.taglayoutmanager.animator.BasedAnimator;
import com.hiray.taglayoutmanager.layoutManager.BlockLayoutManager;


public class MainActivity extends AppCompatActivity {

    RecyclerView recyclerView;
    private ImageAdapter imageAdapter;
    private HirayAdapter hirayAdapter;
    private SameItemSizeAdapter sameItemSizeAdapter;
    private TagAdapter tagAdapter;
    private StaggeredGridAdapter staggerGridLMAdapter;
    private BlockLayoutManager tagLayoutManager;
    private LinearLayoutManager LLM;
    private StaggeredGridLayoutManager SGLM;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
        recyclerView = findViewById(R.id.recycler_view);
        setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

        tagLayoutManager = new BlockLayoutManager();
        LLM = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        SGLM = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        imageAdapter = new ImageAdapter();
        hirayAdapter = new HirayAdapter();
        sameItemSizeAdapter = new SameItemSizeAdapter();
        tagAdapter = new TagAdapter();
        staggerGridLMAdapter = new StaggeredGridAdapter();
        recyclerView.setItemAnimator(new BasedAnimator());
        recyclerView.setLayoutManager(tagLayoutManager);
        recyclerView.setAdapter(sameItemSizeAdapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.adapter_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.block_choice:
                recyclerView.setLayoutManager(tagLayoutManager);
                recyclerView.setAdapter(sameItemSizeAdapter);
                break;
            case R.id.image_choice:
                recyclerView.setLayoutManager(tagLayoutManager);
                recyclerView.setAdapter(imageAdapter);

                break;
            case R.id.flow_choice:
                recyclerView.setLayoutManager(tagLayoutManager);
                recyclerView.setAdapter(tagAdapter);

                break;
            case R.id.mess_choice:
                recyclerView.setLayoutManager(tagLayoutManager);
                recyclerView.setAdapter(hirayAdapter);
                break;
            case R.id.grid:
                recyclerView.setLayoutManager(tagLayoutManager);
                recyclerView.setAdapter(staggerGridLMAdapter);
                break;
            case R.id.staggerGridLM:
                recyclerView.setLayoutManager(SGLM);
                recyclerView.setAdapter(staggerGridLMAdapter);
                break;
            case R.id.AndroidLLM:
                LLM.scrollToPosition(12);
                recyclerView.setLayoutManager(LLM);
                recyclerView.setAdapter(sameItemSizeAdapter);
                break;
            case R.id.DetachAct:
                startActivity(new Intent(this, DetachViewActivity.class));
                break;

            case R.id.LinearAct:
                startActivity(new Intent(this, RecyclerViewActivity.class));
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}
